"use strict";
// 方法装饰器
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    // argsnum 参数个数
    var argsnum = arguments.length
    // targetinfo 被装饰器修饰的目标
    // argsnum=2 装饰器修饰的是类或者构造器参数，targetinof=target[类名]
    // argsnum=4 装饰器修饰的是方法【第四个参数desc等于null】targetinfo=该方法的数据属性【desc = Object.getOwnPropertyDescriptor(target, key)】
    // argsnum=3 装饰器修饰的是方法参数或属性，targetinfo=undefined
    var targetinfo = argsnum < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc;  // s100
    // decorator保存装饰器数组元素
    var decorator;
    // 元数据信息，支持reflect-metadata元数据
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
      targetinfo = Reflect.decorate(decorators, target, key, desc);
    } else {
      // 装饰器循环，倒着循环，说明同一个目标上有多个装饰器，执行循环是倒着执行
      for (var i = decorators.length -1; i >=0; i--) {
        // 如果参数小于3【decorator为类装饰器或者构造器参数装饰器】执行decorator(targetinof)直接执行decorator装饰器，并传递目标targetinfo，这里是类
        //如果参数大于3【decorator为方法装饰器】 直接执行 decorator(target, key, targetinfo)
     //如果参数等于3【decorator为方法参数装饰器或者属性装饰器】，直接执行decorator(target,key)
     //targetinfo最终为各个装饰器执行后的返回值，但如果没有返回值，直接返回第s100行的targetinfo
        targetinfo = (argsnum < 3 ? decorator(targetinfo) : argsnum > 3 ?
            decorator(target, key, targetinfo) : decorator(target, key)) || targetinfo;
        console.log("targetinforesult:", targetinfo)
      }
    }
    return argsnum > 3 && targetinfo && Object.defineProperty(target, key, targetinfo), targetinfo;
}
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
// 不带参数的方法拦截器
// targetClassPrototype 类的原型对象(RoleService.prototype)
// methodname 方法名
// methodDecriptor  数据属性 { value: null, writable: true, enumerable: true, configurable: true }
function MyMethodDecorator(targetClassPrototype, methodname, methodDecriptor) {
    console.log("targetClassPrototype: ", targetClassPrototype);
    console.log("methodname: ", methodname);
    console.log("methodDecriptor: ", methodDecriptor);
    methodDecriptor.value(); // 分配角色...
}
// 不带参数的方法拦截器
function MyMethodDecorator2(methodPath) {
    return function MethodDecorator(targetClassPrototype, methodname, methodDecriptor) {
        console.log("targetClassPrototype: ", targetClassPrototype);
        console.log("methodname: ", methodname);
        console.log("methodPath: ", methodPath);
        console.log("methodDecriptor: ", methodDecriptor);
        methodDecriptor.value(); // 分配角色...
    };
}
// 方法装饰器的拦截器
function MyMethodDecorator3(targetClassPrototype, methodname, methodDecriptor) {
    var method = methodDecriptor.value;
    methodDecriptor.value = function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        console.log("拦截器前 JS逻辑");
        method.call.apply(method, __spreadArray([this], args, false));
        console.log("拦截器后 JS逻辑");
    };
}
// 目标类
var RoleService = /** @class */ (function () {
    function RoleService() {
        this.roleName = "管理员";
    }
    // @MyMethodDecorator
    // @MyMethodDecorator2("/search")
    RoleService.prototype.DistribRoles = function () {
        console.log("分配角色...", this.roleName);
    };
    __decorate([ MyMethodDecorator3 ], RoleService.prototype, "DistribRoles", null);
    return RoleService;
}());
var role = new RoleService();
role.DistribRoles();
